﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <!-- jsp文件头和头部 -->
    <%@ include file="../admin/top.jsp" %>
    <style>
        table tr td img {
            height: 25px;
            border-radius: 8%;
        }
    </style>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <form action="notifyPush/list" method="post" name="userForm" id="userForm">
                    <input type="hidden" name="menuId" value="${page.menuId}">
                    <table style="width: 500px">
                        <tr>
                            <td>
									<span class="input-icon">
										<input style="margin-top: 0px;width: 85%" autocomplete="off" type="text"
                                               name="searchValue" value="${page.searchValue}" placeholder="内容"
                                               id="nav-search-input"/>
									</span>
                            </td>
                            <td>
                                <select class="chzn-select" name="target" data-values="${target}"
                                        style="vertical-align:top;width: 120px;">
                                    <option value="">目标类型</option>
                                    <option value="1"
                                            <c:if test="${target == 1}">selected</c:if> >广播
                                    </option>
                                    <option value="2"
                                            <c:if test="${target == 2}">selected</c:if> >别名
                                    </option>
                                </select>
                            </td>
                            <td style="vertical-align:top;">
                                <button class="btn btn-mini btn-light" type="button" onclick="search();" title="检索">
                                    <i id="nav-search-icon" class="icon-search"></i>
                                </button>
                            </td>
                            <td style="vertical-align:top;">
                                <c:if test="${fn:contains(butSet, 'toAdd')}">
                                    <a class="btn btn-small btn-success" style="z-index: 1055"
                                       onclick="siMenu('z${menu.id}','lm${menu.pmenu.id}', '${menu.id}', '${menu.name}','${menu.url}')">
                                        创建推送
                                    </a>
                                </c:if>
                            </td>
                        </tr>
                    </table>
                    <!-- 检索  -->
                    <table id="table_report" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>推送内容</th>
                            <th>目标类型</th>
                            <th>创建时间</th>
                            <th class="center">操作</th>
                        </tr>
                        </thead>
                        <tbody id="contentTbody">
                        <!-- 开始循环 -->
                        <c:choose>
                            <c:when test="${not empty notifyPushs}">
                                <c:forEach items="${notifyPushs}" var="notifyPush">
                                    <tr style="text-align: center">
                                        <td>${notifyPush.id}</td>
                                        <td>${notifyPush.content}</td>
                                        <td>
                                            <c:if test="${notifyPush.target == 1}">广播</c:if>
                                            <c:if test="${notifyPush.target == 2}">别名</c:if>
                                        </td>
                                        <td>
                                            <fmt:formatDate value="${notifyPush.createTime}"
                                                            pattern="yyyy-MM-dd HH:mm:ss"/>
                                        </td>
                                        <td style="width: 60px;">
                                            <div class='hidden-phone visible-desktop btn-group'>
                                                <c:if test="${notifyPush.isDetail and fn:contains(butSet, 'detail')}">
                                                    <a class='btn btn-mini btn-danger'
                                                       onclick="detail('${notifyPush.id }');" data-toggle="modal"
                                                       data-target="#myModal">
                                                        推送详情
                                                    </a>
                                                </c:if>
                                                <c:if test="${notifyPush.isDetail and fn:contains(butSet, 'recall')}">
                                                    <a class='btn btn-mini btn-danger'
                                                       onclick="recall('${notifyPush.id }');">
                                                        撤回
                                                    </a>
                                                </c:if>
                                                <c:if test="${not notifyPush.isDetail and fn:contains(butSet, 'cancel')}">
                                                    <a class='btn btn-mini btn-danger'
                                                       onclick="cancel('${notifyPush.id }');">
                                                        取消
                                                    </a>
                                                </c:if>
                                            </div>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:when>
                            <c:otherwise>
                                <tr class="main_info">
                                    <td colspan="10" class="center">没有相关数据</td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                        </tbody>
                    </table>
                    <div class="page-header position-relative">
                        <table style="width:100%;">
                            <tr>
                                <td style="vertical-align:top;">
                                    <div class="pagination"
                                         style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
    <i class="icon-double-angle-up icon-only"></i>
</a>

<div id="myModal" class="modal fade" role="dialog" aria-hidden="true" style="width: 900px; left: 35%;display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">推送详情 <span id="pushIdShow"></span></h4>
            </div>
            <div class="modal-body">
                <div id="zhongxin" class="zhongxin-cla">
                    <div style="padding: 5px 5px 5px 5px">
                        <form action="">
                            <table id="table_report" class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>数据/通道</th>
                                    <th>发送数</th>
                                    <th>到达数</th>
                                    <th>点击数</th>
                                </tr>
                                </thead>
                                <tbody id="detailTbody">

                                </tbody>
                            </table>
                        </form>
                    </div>
                    <div id="zhongxin2" class="center" style="display:none">
                        <br/><br/><br/><img src="static/images/jiazai.gif"/><br/>
                        <h4 class="lighter block green"></h4>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>

<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
<script type="text/javascript" src="static/js/myjs/head.js"></script>
<script type="text/javascript">
    $(function () {
        top.hangge();
        //下拉框
        $(".chzn-select").chosen({disable_search: true});
        $(".chzn-select-deselect").chosen({allow_single_deselect: true});
    });

    //检索
    function search() {
        top.jzts();
        $("#userForm").submit();
    }

    //推送详情
    function detail(id) {
        if (id) {
            $.get("notifyPush/detail", {"id": id},
                function (data) {
                    var htmls = "";
                    if (data.data) {
                        $("#pushIdShow").text("ID : " + id)
                        var d = data.data;
                        htmls += '<tr style="text-align: center">'
                        htmls += '<td>推送总数</td>'
                        htmls += '<td>' + d.factory.deliverNum + '</td>'
                        htmls += '<td>' + d.factory.reportNum + '</td>'
                        htmls += '<td>' + d.factory.clickNum + '</td>'
                        htmls += '</tr>'

                        htmls += '<tr style="text-align: center">'
                        htmls += '<td>TCP(Mob通道)</td>'
                        htmls += '<td>' + d.mobpush.deliverNum + '</td>'
                        htmls += '<td>' + d.mobpush.reportNum + '</td>'
                        htmls += '<td>' + d.mobpush.clickNum + '</td>'
                        htmls += '</tr>'

                        htmls += '<tr style="text-align: center">'
                        htmls += '<td>iOS</td>'
                        htmls += '<td>' + d.apns.deliverNum + '</td>'
                        htmls += '<td>' + d.apns.reportNum + '</td>'
                        htmls += '<td>' + d.apns.clickNum + '</td>'
                        htmls += '</tr>'

                        htmls += '<tr style="text-align: center">'
                        htmls += '<td>华为</td>'
                        htmls += '<td>' + d.huawei.deliverNum + '</td>'
                        htmls += '<td>' + d.huawei.reportNum + '</td>'
                        htmls += '<td>' + d.huawei.clickNum + '</td>'
                        htmls += '</tr>'

                        htmls += '<tr style="text-align: center">'
                        htmls += '<td>小米</td>'
                        htmls += '<td>' + d.xiaomi.deliverNum + '</td>'
                        htmls += '<td>' + d.xiaomi.reportNum + '</td>'
                        htmls += '<td>' + d.xiaomi.clickNum + '</td>'
                        htmls += '</tr>'

                        htmls += '<tr style="text-align: center">'
                        htmls += '<td>魅族</td>'
                        htmls += '<td>' + d.flyme.deliverNum + '</td>'
                        htmls += '<td>' + d.flyme.reportNum + '</td>'
                        htmls += '<td>' + d.flyme.clickNum + '</td>'
                        htmls += '</tr>'

                        htmls += '<tr style="text-align: center">'
                        htmls += '<td>OPPO</td>'
                        htmls += '<td>' + d.oppo.deliverNum + '</td>'
                        htmls += '<td>' + d.oppo.reportNum + '</td>'
                        htmls += '<td>' + d.oppo.clickNum + '</td>'
                        htmls += '</tr>'

                        htmls += '<tr style="text-align: center">'
                        htmls += '<td>VIVO</td>'
                        htmls += '<td>' + d.vivo.deliverNum + '</td>'
                        htmls += '<td>' + d.vivo.reportNum + '</td>'
                        htmls += '<td>' + d.vivo.clickNum + '</td>'
                        htmls += '</tr>'

                        htmls += '<tr style="text-align: center">'
                        htmls += '<td>FCM</td>'
                        htmls += '<td>' + d.fcm.deliverNum + '</td>'
                        htmls += '<td>' + d.fcm.reportNum + '</td>'
                        htmls += '<td>' + d.fcm.clickNum + '</td>'
                        htmls += '</tr>'

                    } else {
                        htmls = '<tr class="main_info"><td colspan="10" class="center">没有相关数据</td></tr>'
                    }
                    $("#detailTbody").html(htmls)
                });
        }
    }

    //撤回
    function recall(id) {
        bootbox.confirm("是否撤回[" + id + "]?", function (result) {
            if (result) {
                top.jzts();
                var postParam = {"id": id};
                var url = "<%=basePath%>notifyPush/recall";
                $.post(url, postParam, function (data) {
                    if (data.code == 200) {
                        alert("撤回成功")
                        nextPage(${page.currentPage});
                    } else {
                        alert("撤回失败")
                    }
                });
            }
        });
    }

    //取消
    function cancel(id) {
        bootbox.confirm("是否取消[" + id + "]?", function (result) {
            if (result) {
                top.jzts();
                var postParam = {"id": id};
                var url = "<%=basePath%>notifyPush/cancel";
                $.post(url, postParam, function (data) {
                    if (data.code == 200) {
                        alert("取消成功")
                        nextPage(${page.currentPage});
                    } else {
                        alert("取消失败")
                    }
                });
            }
        });
    }

</script>
</body>
</html>
